<?php

include_once 'CF_TableActCol.php';

class CF_TableAjUpdateOld extends CF_TableActCol {

   	/**
	 *  @var string $keyslist comma delimited list of key variables
	 */		
	var $keyslist;
	
	var $oldvalvar = 'OV_';
	
	var $lookup_lists;
	
	public static $ctl_mapping = array('T'=>'CtlText','D'=>'CtlSelect','A'=>'CtlTextArea','CAL'=>'CtlJQDate','C'=>'CtlCheckbox');
	
	function set_lookup_lists($ar_lists){
		$this->lookup_lists = $ar_lists;
	}		
	
	function set_lookup_list($column,$list){
		$this->lookup_lists[$column] = $list;
	}
	
	
	
	 /**
 * function to make start of row, making each row a form for editing
 * @param int $row_num This is the row number of the dataset
 * @param string $key_string This is the string of key values, defined by make_key_string function
 * @return string Row begining 
 */
	function make_row_start($row_num){
		$formname = $this->tablename . '_' . $this->keys_uid;
		$rowstart .= "<form action='$this->actionpage' name='$formname' method='GET'>";

		$rowstart .= $this->keys_hidden;
		
		if($this->row_status == 'even'){
			$this->row_status = 'odd';
			$rowstart .= "<tr class=\"$this->table_even_class\">";			
		}
		else{
			$this->row_status = 'even';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}

		return $rowstart;
	}
	
   	/**
	 *  Form keylist of key columns
	 */		
	function form_keyslist(){
		$addcomma = '';
		$list = '';
		foreach($this->fieldspec AS $col_name=>$col_spec){
			if(!empty($col_spec['key'])){
				$list .= $addcomma . $col_name;
				$addcomma = ',';
				}
		}
		$this->keyslist = $list;
	}
		
	function make_rowval($value,$column){
		
		$chgname =  $this->name . ".syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
		$row_text .= "<td>";
        $row_text .= $this->make_valuebox($value,$column);
        $row_text .= "</td>";
		return $row_text;			
	}

	function make_control($value,$column){
            $chgname =  $this->name . ".syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
            //$row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
			$ele_params['id'] = $column . "_" . $this->keys_uid;
			$ele_params['name'] = $column;
			$ele_params['do_after_update'] = $chgname;
			
			$type = self::$ctl_mapping[$this->fieldspec[$column]['select']];
			
			$controlhtml .=  MakePhpCtl($type,$ele_params,$value,$this->lookup_lists[$col_name]);
			$ov_name = $this->oldvalvar . $column;
			//$controlhtml .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";		
		return $controlhtml;
	}
	
	
    function make_valuebox($value,$column){
      	if($this->fieldspec[$column]['show'] == 'E'){
         //   $chgname =  $this->name . ".syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
         //   //$row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
		//	$ele_params['id'] = $column . "_" . $this->keys_uid;
		//	$ele_params['name'] = $column;
		//	$ele_params['do_after_update'] = $chgname;
		//	
		//	$type = self::$ctl_mapping[$this->fieldspec[$column]['select']];
		//	
		//	$row_text .=  MakePhpCtl($type,$ele_params,$value,$this->lookup_lists[$col_name]);
			$ov_name = $this->oldvalvar . $column;
			$row_text .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";
			$row_text .= $this->make_control($value,$column);
		}  else if($this->fieldspec[$column]['show'] == 'L') {
            $row_text .= $this->make_lookup_value($column,$value); // NEED TO fun make_format($value, $column) for this one
        }else {
            $row_text .= "$value";
		}
		return $row_text;
    }

	function make_row_end($row_num){
		$rowend .= "</tr></form>\n";
		return $rowend;
	}
	
	function make_supportJS(){
		$this->form_keyslist();
		$jstext = "
	//------" .  $this->name  . " support Javascript from make_supportJS()
	//----- AJAX dataSync settings 
	// support functions in CF_ajtable.js
	$this->name = new CF_ajtable();
	$this->name.url_syncval = \"". $this->actionpage . "\";
	$this->name.keyvariables = '" . $this->keyslist . "';
	$this->name.tablename = '" . $this->name . "'	;
	// End from make_supportJS
		";
		return $jstext;
	}

	function ctl_Text($vaule,$column){
		
	}
	
	
}

?>